package com.RMP
{
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import com.greensock.*;

    public class MenuShell extends Sprite
    {
        var showWhiteBtns:Boolean;
        var btn0Field:TextField;
        public var bookmarksMenu:NavMenu;
        var bar:Sprite;
        var logoSmall:Object;
        var lbIcon:Sprite;
        var fadeSpeed:Number;
        public var hRule1:HorizontalRule;
        public var hRule2:HorizontalRule;
        public var hRule3:HorizontalRule;
        var hoverBar:Sprite;
        var navMenuArray:Array;
        var btn0:Sprite;
        var barOffAlpha:Number = 0.3;
        public var btn:MenuBtn;
        var navCol:NavCol;
        var btn0BG:Sprite;
        var currNavId:int;
        var overBar:Boolean = false;
        var myRoot:MovieClip;
        var tempList0:XMLList;
        var tempList2:XMLList;
        var tempList3:XMLList;
        var tempList1:XMLList;
        var tempList4:XMLList;
        public var practiceMenu:NavMenu;
        public var lightboxMenu:NavMenu;
        public var contactMenu:NavMenu;
        public var newsMenu:NavMenu;
        public var projectsMenu:NavMenu;
        public var navArray:Array;

        public function MenuShell(param1:MovieClip, param2:Number, param3:Boolean) : void
        {
            var _loc_4:String = null;
            overBar = false;
            barOffAlpha = 0.3;
            myRoot = param1;
            fadeSpeed = param2;
            showWhiteBtns = param3;
            if (myRoot.localImagesXML.image.length() > 0 || myRoot.localPagesXML.page.length() > 0)
            {
                _loc_4 = "Bookmarks " + String(myRoot.localImagesXML.image.length() + myRoot.localPagesXML.page.length());
            }
            else
            {
                _loc_4 = "Bookmarks";
            }
            navArray = new Array(["Projects"], ["Practice"], ["Contact"], ["News"], [_loc_4], ["Search"]);
            tempList0 = new XMLList(myRoot.myXML.nav.projects.tier0);
            tempList1 = new XMLList(myRoot.myXML.nav.practice.tier0);
            tempList2 = new XMLList(myRoot.myXML.nav.contact.tier0);
            tempList3 = new XMLList(myRoot.myXML.nav.news.item);
            tempList4 = new XMLList(myRoot.myXML.nav.bookmarks.tier0);
            buildBar();
            hRule1 = new HorizontalRule();
            hRule1.alpha = 0;
            addChild(hRule1);
            hRule2 = new HorizontalRule();
            hRule2.alpha = 1;
            addChild(hRule2);
            hRule3 = new HorizontalRule();
            hRule3.alpha = 1;
            this.addEventListener(MouseEvent.ROLL_OVER, barRollOver, false, 0, true);
            this.addEventListener(MouseEvent.ROLL_OUT, barRollOut, false, 0, true);
            myRoot.stage.addEventListener(Event.RESIZE, onResizer, false, 0, true);
            doResize();
            return;
        }

        public function hRule1Off() : void
        {
            TweenMax.to(hRule1, fadeSpeed, {alpha:0, overwrite:true});
            return;
        }

        function barRollOut(event:MouseEvent) : void
        {
            var _loc_2:int = 0;
            this.removeEventListener(MouseEvent.MOUSE_MOVE, barMouseChecker);
            if (currNavId == 6)
            {
            }
            else
            {
                _loc_2 = 0;
                while (_loc_2 < navArray.length)
                {
                    
                    if (_loc_2 == currNavId)
                    {
                        TweenMax.to(navArray[_loc_2][1], fadeSpeed, {alpha:1, overwrite:true});
                    }
                    else
                    {
                        TweenMax.to(navArray[_loc_2][1], fadeSpeed, {alpha:barOffAlpha, overwrite:true});
                    }
                    _loc_2++;
                }
            }
            return;
        }

        public function hRule1On() : void
        {
            TweenMax.to(hRule1, fadeSpeed, {alpha:1, overwrite:true});
            return;
        }

        function barMouseChecker(event:MouseEvent) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            if (mouseY <= bar.height)
            {
                if (currNavId == 6)
                {
                }
                else
                {
                    _loc_2 = 0;
                    while (_loc_2 < navArray.length)
                    {
                        
                        TweenMax.to(navArray[_loc_2][1], fadeSpeed, {alpha:1, overwrite:true});
                        _loc_2++;
                    }
                }
            }
            else if (currNavId == 6)
            {
            }
            else
            {
                _loc_3 = 0;
                while (_loc_3 < navArray.length)
                {
                    
                    if (_loc_3 == currNavId)
                    {
                        TweenMax.to(navArray[_loc_3][1], fadeSpeed, {alpha:1, overwrite:true});
                    }
                    else
                    {
                        TweenMax.to(navArray[_loc_3][1], fadeSpeed, {alpha:barOffAlpha, overwrite:true});
                    }
                    _loc_3++;
                }
            }
            return;
        }

        function barRollOver(event:MouseEvent) : void
        {
            var _loc_2:int = 0;
            this.addEventListener(MouseEvent.MOUSE_MOVE, barMouseChecker, false, 0, true);
            if (currNavId == 6)
            {
            }
            else
            {
                _loc_2 = 0;
                while (_loc_2 < navArray.length)
                {
                    
                    TweenMax.to(navArray[_loc_2][1], fadeSpeed, {alpha:1, overwrite:true});
                    _loc_2++;
                }
            }
            return;
        }

        public function updateBookmark() : void
        {
            if (currNavId != 4 && navArray[4][1] != undefined)
            {
                navArray[4][1].alpha = 1;
                TweenMax.to(navArray[4][1].field, fadeSpeed, {tint:16777215, overwrite:true, onComplete:function ()
            {
                TweenMax.to(navArray[4][1].field, fadeSpeed, {tint:12500670, overwrite:true});
                TweenMax.to(navArray[4][1], fadeSpeed, {alpha:barOffAlpha, overwrite:true});
                return;
            }
            });
            }
            return;
        }

        public function switchCols(param1:Number) : void
        {
            var _loc_2:int = 0;
            fadeBtns();
            if (param1 == 0)
            {
                myRoot.pathNames[0] = "projects";
            }
            else if (param1 == 1)
            {
                myRoot.pathNames[0] = "practice";
            }
            else if (param1 == 2)
            {
                myRoot.pathNames[0] = "contact";
            }
            else if (param1 == 3)
            {
                myRoot.pathNames[0] = "news";
            }
            else if (param1 == 4)
            {
                myRoot.pathNames[0] = "bookmarks";
            }
            else if (param1 == 5)
            {
                myRoot.pathNames[0] = "search";
            }
            _loc_2 = 0;
            while (_loc_2 < navMenuArray.length)
            {
                
                if (_loc_2 != param1)
                {
                    if (navMenuArray[_loc_2] != undefined)
                    {
                        navMenuArray[_loc_2].fadeOutShell();
                        TweenMax.to(navArray[_loc_2], fadeSpeed, {tint:12500670, overwrite:true});
                    }
                }
                else if (navMenuArray[_loc_2] != undefined)
                {
                    navMenuArray[_loc_2].fadeInShell();
                }
                _loc_2++;
            }
            return;
        }

        function onResizer(event:Event)
        {
            doResize();
            return;
        }

        public function hRule2Off() : void
        {
            hRule2.visible = false;
            return;
        }

        function btnRollOver(event:MouseEvent) : void
        {
            if (currNavId == 6)
            {
                TweenMax.to(event.currentTarget.field, fadeSpeed, {tint:12500670, overwrite:true});
            }
            else
            {
                TweenMax.to(event.currentTarget.field, fadeSpeed, {tint:16777215, overwrite:true});
            }
            return;
        }

        function doResize() : void
        {
            var _loc_1:* = undefined;
            var _loc_2:int = 0;
            bar.width = Math.round(myRoot.headerW);
            bar.height = Math.round(myRoot.headerH);
            hoverBar.width = bar.width;
            hoverBar.height = bar.height;
            btn0.x = 0;
            btn0.y = 2 * myRoot.unitW / 75;
            btn0BG.y = -2;
            btn0BG.width = 4 * (myRoot.unitW + myRoot.gutterW);
            btn0BG.height = bar.height;
            _loc_1 = new Array(4 * (myRoot.unitW + myRoot.gutterW), 5 * (myRoot.unitW + myRoot.gutterW), 6 * (myRoot.unitW + myRoot.gutterW), 7 * (myRoot.unitW + myRoot.gutterW), 8 * (myRoot.unitW + myRoot.gutterW), 10 * (myRoot.unitW + myRoot.gutterW));
            _loc_2 = 0;
            while (_loc_2 < navArray.length)
            {
                
                navArray[_loc_2][1].x = Math.round(_loc_1[_loc_2]);
                navArray[_loc_2][1].y = 2 * myRoot.unitW / 75;
                var _loc_3:* = myRoot.unitW / 75;
                navArray[_loc_2][1].field.scaleY = myRoot.unitW / 75;
                navArray[_loc_2][1].field.scaleX = _loc_3;
                if (navMenuArray[_loc_2] != undefined)
                {
                    navMenuArray[_loc_2].x = Math.round(_loc_1[_loc_2]);
                    navMenuArray[_loc_2].y = 28 * myRoot.unitW / 75;
                }
                if (_loc_2 == 4)
                {
                    navArray[_loc_2][1].btnOver.y = -2;
                    navArray[_loc_2][1].btnOver.width = 2 * (myRoot.unitW + myRoot.gutterW);
                    navArray[_loc_2][1].btnOver.height = bar.height;
                }
                else if (_loc_2 == 5)
                {
                    navArray[_loc_2][1].btnOver.y = -2;
                    navArray[_loc_2][1].btnOver.width = 2 * myRoot.unitW + myRoot.gutterW;
                    navArray[_loc_2][1].btnOver.height = bar.height;
                }
                else
                {
                    navArray[_loc_2][1].btnOver.y = -2;
                    navArray[_loc_2][1].btnOver.width = myRoot.unitW + myRoot.gutterW;
                    navArray[_loc_2][1].btnOver.height = bar.height;
                }
                _loc_2++;
            }
            var _loc_3:* = myRoot.unitW / 75;
            logoSmall.scaleY = myRoot.unitW / 75;
            logoSmall.scaleX = _loc_3;
            logoSmall.width = Math.round(logoSmall.width);
            logoSmall.height = Math.round(logoSmall.height);
            hRule1.x = Math.round(4 * (myRoot.unitW + myRoot.gutterW));
            hRule1.y = Math.round(bar.height + myRoot.unitH + 4 / 9 * myRoot.gutterH);
            hRule1.width = Math.round(8 * myRoot.unitW + 7 * myRoot.gutterW);
            hRule1.height = 1;
            hRule2.y = Math.round(bar.height + 2 * myRoot.unitH + myRoot.gutterH);
            hRule2.width = Math.round(myRoot.gridCurrW);
            hRule2.height = 1;
            hRule3.y = Math.round(myRoot.gridCurrH);
            hRule3.width = Math.round(myRoot.gridCurrW);
            hRule3.height = 1;
            return;
        }

        function btn0RollOver(event:MouseEvent) : void
        {
            if (currNavId == 6)
            {
            }
            else
            {
                TweenMax.to(logoSmall, fadeSpeed, {alpha:0.7, overwrite:true});
            }
            return;
        }

        function buildCols(param1:int) : void
        {
            if (param1 == 0)
            {
                projectsMenu = new NavMenu(myRoot, fadeSpeed, "tier0", "projectsMenu", tempList0);
                projectsMenu.name = "projectsMenu";
                navMenuArray[0] = projectsMenu;
                navMenuArray[0].visible = false;
                navMenuArray[0].alpha = 0;
                addChild(navMenuArray[0]);
                tempList0 = null;
            }
            if (param1 == 1)
            {
                practiceMenu = new NavMenu(myRoot, fadeSpeed, "tier0", "practiceMenu", tempList1);
                practiceMenu.name = "practiceMenu";
                navMenuArray[1] = practiceMenu;
                navMenuArray[1].visible = false;
                navMenuArray[1].alpha = 0;
                addChild(navMenuArray[1]);
                tempList1 = null;
            }
            if (param1 == 2)
            {
                contactMenu = new NavMenu(myRoot, fadeSpeed, "tier0", "contactMenu", tempList2);
                contactMenu.name = "contactMenu";
                navMenuArray[2] = contactMenu;
                navMenuArray[2].visible = false;
                navMenuArray[2].alpha = 0;
                addChild(navMenuArray[2]);
                tempList2 = null;
            }
            if (param1 == 3)
            {
                newsMenu = new NavMenu(myRoot, fadeSpeed, "tier0", "newsMenu", tempList3);
                newsMenu.name = "newsMenu";
                navMenuArray[3] = newsMenu;
                navMenuArray[3].visible = false;
                navMenuArray[3].alpha = 0;
                addChild(navMenuArray[3]);
                tempList3 = null;
            }
            if (param1 == 4)
            {
                bookmarksMenu = new NavMenu(myRoot, fadeSpeed, "tier0", "bookmarksMenu", tempList4);
                bookmarksMenu.name = "bookmarksMenu";
                navMenuArray[4] = bookmarksMenu;
                navMenuArray[4].visible = false;
                navMenuArray[4].alpha = 0;
                addChild(navMenuArray[4]);
                tempList4 = null;
            }
            if (param1 == 5)
            {
                myRoot.clickPathNames = ["search"];
                myRoot.updateAddress("/" + "search" + "/");
            }
            doResize();
            return;
        }

        function btnRollOut(event:MouseEvent) : void
        {
            if (currNavId != event.currentTarget.idNum)
            {
                if (currNavId == 6)
                {
                    TweenMax.to(event.currentTarget.field, fadeSpeed, {tint:16777215, overwrite:true});
                }
                else
                {
                    TweenMax.to(event.currentTarget.field, fadeSpeed, {tint:12500670, overwrite:true});
                }
            }
            return;
        }

        function fadeBtns() : void
        {
            var _loc_1:int = 0;
            _loc_1 = 0;
            while (_loc_1 < navArray.length)
            {
                
                if (_loc_1 != currNavId)
                {
                    if (currNavId == 6)
                    {
                        TweenMax.to(navArray[_loc_1][1].field, fadeSpeed, {tint:16777215, overwrite:true});
                    }
                    else
                    {
                        TweenMax.to(navArray[_loc_1][1].field, fadeSpeed, {tint:12500670, overwrite:true});
                    }
                }
                _loc_1++;
            }
            return;
        }

        function btn0RollOut(event:MouseEvent) : void
        {
            if (currNavId == 6)
            {
                TweenMax.to(logoSmall, fadeSpeed, {alpha:1, overwrite:true});
            }
            else
            {
                TweenMax.to(logoSmall, fadeSpeed, {alpha:1, overwrite:true});
            }
            return;
        }

        public function hRule3On() : void
        {
            hRule3.visible = true;
            return;
        }

        function btn0Click(event:MouseEvent) : void
        {
            TweenMax.to(logoSmall, fadeSpeed, {alpha:1, overwrite:true});
            myRoot.updateAddress("");
            return;
        }

        public function hRule2On() : void
        {
            hRule2.visible = true;
            return;
        }

        function btnClick(event:MouseEvent) : void
        {
            currNavId = event.currentTarget.idNum;
            myRoot.currNavId = currNavId;
            if (navMenuArray[currNavId] == undefined)
            {
                buildCols(currNavId);
            }
            switchCols(event.currentTarget.idNum);
            TweenMax.to(event.currentTarget.field, fadeSpeed, {tint:16777215, overwrite:true});
            return;
        }

        function buildBar() : void
        {
            var _loc_1:* = undefined;
            var _loc_2:int = 0;
            hoverBar = new Sprite();
            hoverBar.graphics.beginFill(16777215, 1);
            hoverBar.graphics.drawRect(0, 0, 999, 28);
            hoverBar.graphics.endFill();
            addChild(hoverBar);
            bar = new Sprite();
            bar.graphics.beginFill(myRoot.coldColor, 1);
            bar.graphics.drawRect(0, 0, 999, 28);
            bar.graphics.endFill();
            addChild(bar);
            _loc_1 = new TextFormat();
            _loc_1.font = new BodoniEmbed().fontName;
            _loc_1.size = 17;
            _loc_1.letterSpacing = -0.6;
            _loc_1.leftMargin = 0;
            _loc_1.rightMargin = 0;
            _loc_1.color = "0xFFFFFF";
            btn0 = new Sprite();
            btn0.useHandCursor = true;
            btn0.mouseEnabled = true;
            btn0.buttonMode = true;
            btn0.mouseChildren = true;
            btn0.addEventListener(MouseEvent.MOUSE_OVER, btn0RollOver, false, 0, true);
            btn0.addEventListener(MouseEvent.MOUSE_OUT, btn0RollOut, false, 0, true);
            btn0.addEventListener(MouseEvent.CLICK, btn0Click, false, 0, true);
            btn0BG = new Sprite();
            btn0BG.graphics.beginFill(16777215, 0);
            btn0BG.graphics.drawRect(0, 0, 1, 1);
            btn0BG.graphics.endFill();
            btn0.addChild(btn0BG);
            btn0Field = new TextField();
            btn0Field.name = "btn0Field";
            btn0Field.autoSize = "left";
            btn0Field.antiAliasType = AntiAliasType.ADVANCED;
            btn0Field.gridFitType = GridFitType.PIXEL;
            btn0Field.selectable = false;
            btn0Field.embedFonts = true;
            btn0Field.text = "Richard Meier & Partners Architects LLP";
            btn0Field.setTextFormat(_loc_1);
            btn0Field.alpha = 1;
            btn0Field.x = 0;
            btn0Field.y = -1;
            logoSmall = new Bitmap(new LogoSmall(0, 0));
            btn0.addChild(logoSmall);
            logoSmall.smoothing = true;
            logoSmall.x = 2;
            logoSmall.y = 2;
            addChild(btn0);
            navMenuArray = new Array();
            navMenuArray.length = 4;
            _loc_2 = 0;
            while (_loc_2 < navArray.length)
            {
                
                btn = new MenuBtn(myRoot, fadeSpeed, navArray[_loc_2][0]);
                btn.addEventListener(MouseEvent.MOUSE_OVER, btnRollOver, false, 0, true);
                btn.addEventListener(MouseEvent.MOUSE_OUT, btnRollOut, false, 0, true);
                btn.addEventListener(MouseEvent.CLICK, btnClick, false, 0, true);
                btn.idNum = _loc_2;
                btn.name = "btn" + _loc_2;
                btn.mouseEnabled = true;
                btn.buttonMode = true;
                btn.mouseChildren = true;
                navArray[_loc_2].push(btn);
                addChild(btn);
                _loc_2++;
            }
            return;
        }

        public function autoSwitch(param1:Number)
        {
            var _loc_2:int = 0;
            currNavId = param1;
            myRoot.currNavId = currNavId;
            if (navMenuArray[currNavId] == undefined)
            {
                buildCols(currNavId);
            }
            fadeBtns();
            _loc_2 = 0;
            while (_loc_2 < navArray.length)
            {
                
                if (_loc_2 != currNavId)
                {
                    if (navMenuArray[_loc_2] != undefined)
                    {
                        navMenuArray[_loc_2].fadeOutShell();
                    }
                    if (currNavId == 6)
                    {
                        TweenMax.to(navArray[_loc_2][1].field, fadeSpeed, {tint:16777215, overwrite:true});
                    }
                    else
                    {
                        TweenMax.to(navArray[_loc_2][1].field, fadeSpeed, {tint:12500670, overwrite:true});
                    }
                }
                else
                {
                    if (navMenuArray[_loc_2] != undefined)
                    {
                        navMenuArray[_loc_2].fadeInShellAuto(1);
                    }
                    TweenMax.to(navArray[_loc_2][1].field, fadeSpeed, {tint:16777215, overwrite:true});
                }
                _loc_2++;
            }
            barMouseChecker(null);
            return;
        }

        public function hRule3Off() : void
        {
            hRule3.visible = false;
            return;
        }

        public function fadeInShell() : void
        {
            TweenMax.to(this, fadeSpeed, {alpha:1, overwrite:true});
            return;
        }

    }
}
